﻿-- Author      : Kurapica
-- Create Date : 10/28/2008

--[[
	In-Game Addon System
	Studio
	Core Part
--]]
do	
    local L = IGAS:NewLocal("IGAS.Studio")
    local pairs = pairs
    local ipairs = ipairs
    local type = type
    local error = error
	local _Widget = IGAS.GUI.Widget
    local CreateFrame = IGAS.GUI.CreateFrame
    local GetWrapper = IGAS.GUI.GetWrapper
    
	------------------------------------------------------
	------------------- Naming Space ---------------------
	------------------------------------------------------
	IGAS.Studio = {}
	IGAS.Studio.Widget = {}
	IGAS.Studio.Advance = {}
	
	------------------------------------------------------
	------------------- Base Frame ---------------------
	------------------------------------------------------
	-- Base Form for all other forms in Studio
    local coreF = CreateFrame("Frame", "IGAS_STUDIO", WorldFrame)
	coreF:SetAllPoints(WorldFrame)
	coreF.MouseEnabled = true
	coreF.Visible = false
	
	IGAS.Studio.UIParent = coreF
	
	------------------------------------------------------
	------------------- MiniMap Icon ---------------------
	------------------------------------------------------
	local icon = CreateFrame("MinimapIcon", "IGAS_MapIcon", coreF)
    icon:SetIcon("Interface\\Icons\\Ability_Creature_Cursed_04")
    icon.Tooltip = "IGAS Studio"
    icon.Visible = true
	function icon:OnMouseUp()
		if coreF.Visible then
			UIParent:Show()
			coreF.Visible = false
		else
			UIParent:Hide()
			coreF.Visible = true
		end
    end
	
	------------------------------------------------------
	------------------- functions ---------------------
	------------------------------------------------------
	local _DefaultValue = {}
	local orderT = {}
	
	-- Default Value
	local function RegisterDefaultValue(objectType, prototype, frame)
		local property
		local propertyName
		
		if prototype.Base then
			RegisterDefaultValue(objectType, prototype.Base, frame)
		end

		for propertyName, property in pairs(prototype.Property) do
			if not orderT[propertyName] then
				orderT[propertyName] = true
				
				if property["Get"] and property["Set"] and property["Type"] and 
					(property["Type"]["Type"] == "number" or property["Type"]["Type"] == "string" or 
					property["Type"]["Type"] == "boolean" or property["Type"]["Type"] == "enum") then
					
					_DefaultValue[objectType][propertyName] = frame[propertyName]
				end
			end
		end
	end
	
	function IGAS.Studio:RegisterDefaultValue(objectType)
		if _DefaultValue[objectType] then
			return
		end
		
		local frame = CreateFrame(objectType, nil, self)
		
		_DefaultValue[objectType] = {}
		RegisterDefaultValue(objectType, objectType, frame)		
		table.wipe(orderT)
		
		frame:Dispose()
	end
	
	function IGAS.Studio:GetDefaultValue(objectType, property)
		return (_DefaultValue[objectType] and _DefaultValue[objectType][property]) or nil
	end
	
	-- Register Advance settings Frame
	function IGAS.Studio:RegisterAdvanceFrame(objectType, frame)
		if objectType and frame and frame["SetFrame"] and frame["GetFrame"] then
			IGAS.Studio.Advance[objectType] = frame
		end
	end
end